function NestedToFlat(data) {
  let result = [];

  for (let i = 0; i < data.length; i++) {
    result.push({
      id: data[i]['id'],
      pid: data[i]['pid'],
      name: data[i]['name']
    });

    if (data[i]['children']) {
      result = result.concat(this.demo(data[i].children));
    }
  }

  return result;
}
